home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Science
/
RLaB
/
examples
/
euclid.r
< prev
next >
Wrap
Text File
|
1994-04-25
|
492b
|
29 lines
//-------------------------------------------------------------------//
// Euclid's algorithm
//
// Syntax: euclid ( M , N )
// Description:
// Euclid's algorithm computes the greatest common divisor of two
// integers (M, and N).
//-------------------------------------------------------------------//
euclid = function ( M , N )
{
local( m , n , r );
m = M;
n = N;
r = 1;
while(r)
{
r = mod(m,n);
if(r == 0) { break; }
m = n;
n = r;
}
return n;
};